#!/usr/bin/env ruby

LKP_SRC = ENV['LKP_SRC'] || File.dirname(File.dirname(File.realpath($PROGRAM_NAME)))
require "#{LKP_SRC}/lib/tests/stats"
stats = LKP::Stats.new

$stdin.each_line do |line|
  case line
  when /^preload duration: (\d+\.\d+)$/
    puts "LAT.preload_duration: #{$1}"
  when /^\[([0-9A-Za-z_%]+)\], ([0-9A-Za-z_%=\(\)]+), ([0-9.]+)$/
    k1 = $1
    k2 = $2
    val = $3
    next if k1 =~ /^(Operations|Return=OK)/
    case k2
    when /\(ms|us\)/
      type = 'LAT'
    when /ops\/sec/
      type = 'RATE'
    when /%/
      type = 'PERCENT'
    else
      next
    end
    stats.append_metric("#{type}.#{k1}.#{k2}", val)
  else
    next
  end
end

stats.dump
